package com.app.micaihu.adapter.PagerAdapter;

import android.view.View;
import android.view.ViewGroup;

import androidx.viewpager.widget.PagerAdapter;

import java.util.ArrayList;

/**
 * 公用的viewpager的适配器
 */
public class CommonPagerAdapter extends PagerAdapter {
	private ArrayList<View> list;

	public CommonPagerAdapter(ArrayList<View> list) {
		this.list=list;
	}

	@Override
	public int getCount() {
		return list!=null&&!list.isEmpty()?list.size():0;
	}
	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		container.addView(list.get(position));
		return list.get(position);
	}
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView(list.get(position));
	}
	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0==arg1;
	}
	
}
